//
// Created by aaa on 2025/7/15.
//

#include<bits/stdc++.h>

using namespace std;

const int N = 1e4 + 10;

int dp[N][2],w[N];
int n;

//6
//7 1 5 3 4 6
int main(){
    cin >> n;
    for(int i = 1;i <= n;i++) cin >> w[i];

    //分类转移
    dp[1][0] = 0,dp[1][1] = -w[1];
    for(int i = 2;i <= n;i++){
        dp[i][0] = max(dp[i-1][0],dp[i-1][1]+w[i]);
        dp[i][1] = max(dp[i-1][1],dp[i-1][0]-w[i]);
    }
    cout << dp[n][0];
    return 0;
}